home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _4B4D270DFD3D4683A79A6F9FCF120AE3 < prev    next >
Encoding:
Text File  |  2004-01-06  |  6.6 KB  |  256 lines

  1. MissionHint = {
  2.     type = "Sound",
  3.  
  4.     Properties = {
  5.         Hints = {
  6.             sndHint1="",
  7.             sndHint2="",
  8.             sndHint3="",
  9.             sndHint4="",
  10.             sndHint5="",
  11.             sndHint6="",
  12.             sndHint7="",
  13.             sndHint8="",
  14.             sndHint9="",
  15.             sndHint10="",
  16.         },
  17.         sndSkipAcknowledge="",
  18.         iAllowedToSkip=3,
  19.         iVolume=255,
  20.         bLoop=0,    -- Loop sound.
  21.         bOnce=0,
  22.         bEnabled=1,
  23.  
  24.     },
  25.     skipped=0,
  26.     HintCount = 1,
  27.     SkipCount = 0,
  28.     Editor={
  29.         Model="Objects/Editor/Sound.cgf",
  30.     },    
  31. }
  32.  
  33. function MissionHint:OnSave(stm)
  34.     --WriteToStream(stm,self.Properties);
  35.     stm:WriteInt(self.started);
  36.     stm:WriteInt(self.HintCount);
  37. end
  38.  
  39. function MissionHint:OnLoad(stm)
  40.     --self.Properties=ReadFromStream(stm);
  41.     self:OnReset();
  42.     self.started = stm:ReadInt();
  43.     self.HintCount = stm:ReadInt();
  44.  
  45.     if self.started==1 then
  46.         self:Play();
  47.     end
  48. end
  49.  
  50. ----------------------------------------------------------------------------------------
  51. function MissionHint:OnPropertyChange()
  52.     if (self.soundName ~= self.Properties.sndSource or self.sound == nil or self.Properties.bLoop ~= self.loop) then
  53.         if (self.started==1) then
  54.             self:Play();
  55.         end
  56.         self.loop = self.Properties.bLoop;
  57.     end
  58.     self:OnReset();
  59.     if (self.sound ~= nil) then
  60.         if (self.Properties.bLoop~=0) then
  61.             Sound:SetSoundLoop(self.sound,1);
  62.         else
  63.             Sound:SetSoundLoop(self.sound,0);
  64.         end;
  65.  
  66.         Sound:SetSoundVolume(self.sound,self.Properties.iVolume);
  67.         Sound:SetSoundProperties(self.sound,self.Properties.fFadeValue);            
  68.     end;
  69. end
  70.  
  71. ----------------------------------------------------------------------------------------
  72. function MissionHint:OnReset()
  73.     self:NetPresent(nil);
  74.     -- Set basic sound params.
  75.     --System:LogToConsole("Reset SP");
  76.     --System:LogToConsole("self.Properties.bPlay:"..self.Properties.bPlay..", self.started:"..self.started);
  77.     
  78.     System:LogToConsole("Resetting now");
  79.  
  80.     self.SkipCount = 0;
  81.     self.HintCount = 1;
  82.     self.skipped = 0;
  83.     self:StopSound();
  84.     self.sound = nil;
  85.  
  86.     Sound:SetGroupScale(SOUNDSCALE_MASTER, getglobal("s_SFXVolume"));
  87. end
  88. ----------------------------------------------------------------------------------------
  89. MissionHint["Server"] = {
  90.     OnInit= function (self)
  91.         self:EnableUpdate(0);
  92.         self.started = 0;
  93.     end,
  94.     OnShutDown= function (self)
  95.     end,
  96. }
  97.  
  98. ----------------------------------------------------------------------------------------
  99. MissionHint["Client"] = {
  100.     ----------------------------------------------------------------------------------------
  101.     OnInit = function(self)
  102.         self:EnableUpdate(0);
  103.         --System:LogToConsole("OnInit");
  104.         self.started = 0;
  105.         self.loop = self.Properties.bLoop;
  106.         self.soundName = "";
  107.  
  108.         if (self.Properties.bPlay==1) then
  109.             self:Play();
  110.         end
  111.  
  112.     end,
  113.  
  114.     ----------------------------------------------------------------------------------------
  115.     OnTimer= function(self)
  116.         if (not Sound:IsPlaying(self.sound)) then
  117.             System:Log("sound stopped - sound scale to normal");
  118.             Sound:StopSound(self.sound)
  119.             self.sound = nil;
  120.             Sound:SetGroupScale(SOUNDSCALE_MASTER, getglobal("s_SFXVolume"));
  121.         else
  122.             -- Sound still playing.
  123.             -- set another timer.
  124.             self:SetTimer(1000);
  125.         end
  126.     end,
  127.     ----------------------------------------------------------------------------------------
  128.     OnShutDown = function(self)
  129.         self:StopSound();
  130.     end,
  131. }
  132.  
  133. ----------------------------------------------------------------------------------------
  134. function MissionHint:Play()
  135.  
  136.     --System:LogToConsole("\005 Now playing with "..self.SkipCount.." skip and "..self.HintCount.." hint");
  137.  
  138.     System:Log("Now playing with "..self.SkipCount.." skip and "..self.HintCount.." hint");
  139.  
  140.     if ((self.Properties.bEnabled == 0 ) or (self.skipped == 1) ) then 
  141.         do return end;
  142.     end
  143.  
  144.     if( Sound:IsPlaying(self.sound) )then
  145.         Sound:StopSound(self.sound);
  146.         Sound:SetGroupScale(SOUNDSCALE_MASTER, getglobal("s_SFXVolume"));
  147.         self.SkipCount = self.SkipCount+1;
  148.     end
  149.  
  150.     self.sound = nil;
  151.  
  152.     if (self.SkipCount > self.Properties.iAllowedToSkip) then 
  153.         if (sndSkipAcknowledge ~= "") then
  154.             self.skipped = 1;
  155.             self.sound = Sound:LoadSound(self.Properties.sndSkipAcknowledge);
  156.             self.soundName = self.Properties.sndSkipAcknowledge;
  157.         end
  158.     else
  159.         if (self.sound == nil) then
  160.             self:LoadSnd();
  161.             if (self.sound == nil) then
  162.                 return;
  163.             end;
  164.         end
  165.     end
  166.  
  167.  
  168.     if (self.Properties.bLoop~=0) then
  169.         Sound:SetSoundLoop(self.sound,1);
  170.     else
  171.         Sound:SetSoundLoop(self.sound,0);
  172.     end;
  173.  
  174.     Sound:SetSoundVolume(self.sound,self.Properties.iVolume);
  175.  
  176.     --System:LogToConsole("Playing sound");
  177.     --local len=Sound:GetSoundLength(self.sound);
  178.     --System:Log("length="..len);
  179.     --self:SetTimer(80*1000);
  180.     --self:SetTimer((len)*1000);
  181.     
  182.     self:SetTimer( 1000 );
  183.  
  184.     Game:PlaySubtitle(self.sound);
  185.  
  186.     --Sound:PlaySoundFadeUnderwater(self.sound);
  187.     --System:LogToConsole( "Play Sound" );
  188.  
  189.     Sound:SetGroupScale(SOUNDSCALE_MASTER, getglobal("s_SFXVolume")*0.5);
  190.     
  191. end
  192.  
  193. ----------------------------------------------------------------------------------------
  194. function MissionHint:StopSound()
  195.  
  196.     if (self.Properties.bEnabled == 0 ) then 
  197.         do return end;
  198.     end
  199.  
  200. --    if (self.sound ~= nil and Sound:IsPlaying(self.sound) ) then
  201.     if (self.sound ~= nil ) then
  202.         Sound:StopSound(self.sound);
  203.         --System:LogToConsole( "Stop Sound" );
  204.         self.sound = nil;
  205.     end
  206.     self.started = 0;
  207. end
  208.  
  209. ----------------------------------------------------------------------------------------
  210. function MissionHint:LoadSnd()
  211.  
  212.     if (self.Properties.Hints["sndHint"..self.HintCount] ~= "") then
  213.         self.sound = Sound:LoadSound(self.Properties.Hints["sndHint"..self.HintCount]);
  214.         self.HintCount = self.HintCount + 1;
  215.     end
  216.  
  217.     self.soundName = self.Properties.Hints["sndHint"..self.HintCount];
  218. end
  219.  
  220. ----------------------------------------------------------------------------------------
  221. function MissionHint:Event_Play( sender )
  222.  
  223.     if(self.started~=0) then
  224.         return
  225.     end
  226.     self:Play();
  227.     --BroadcastEvent( self,"Play" );
  228. end
  229.  
  230. -------------------------------------------------------------------------------
  231. -- Stop Event
  232. -------------------------------------------------------------------------------
  233. function MissionHint:Event_Stop( sender )
  234.     self:StopSound();
  235.     --BroadcastEvent( self,"Stop" );
  236. end
  237.  
  238. function MissionHint:Event_Enable( sender )
  239.     self.Properties.bEnabled = 1;
  240.     --BroadcastEvent( self,"Stop" );
  241. end
  242.  
  243. function MissionHint:Event_Disable( sender )
  244.     self.Properties.bEnabled = 0;
  245.     --BroadcastEvent( self,"Stop" );
  246. end
  247.  
  248.  
  249. ----------------------------------------------------------------------------------------
  250. function MissionHint:OnWrite( stm )
  251. end
  252.  
  253. ----------------------------------------------------------------------------------------
  254. function MissionHint:OnRead( stm )
  255. end
  256.